package org.unedvirtualslate.gui;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import org.unedvirtualslate.logic.CanvasPanel;
import org.unedvirtualslate.logic.ToolButtonPanelLogic;

public class ToolButtonPanel extends JPanel {

	/**
	 * Generated serial.
	 */
	private static final long serialVersionUID = -856369841321350007L;
	private ToolButtonPanelLogic logic;
	private JButton jbtnLine;
	private JButton jbtnFreeHand;
	private JButton jbtnSquare;
	private JButton jbtnOval;
	private JButton jbtnRounRectangle;
	
	/**
	 * Constructor por defecto.
	 */
	public ToolButtonPanel(){
		super();
		this.logic = new ToolButtonPanelLogic();
		initialize();
	}
	
	/**
	 * Constructor parametrizado, hay que pasarle la lógica de los botones.
	 * @param logic
	 */
	public ToolButtonPanel(ToolButtonPanelLogic logic){
		super();
		this.logic = logic;
		initialize();
	}
	
	/**
	 * Este método nos iniciará todos los botones del panel colocandolos en su sitio.
	 */
	private void initialize(){
		this.add(getJbtnFreeHand());
		this.add(getJbtnLine());
		this.add(getJbtnSquare());
		this.add(getJbtnOval());
		this.add(getJbtnRoundRectangle());
	}
	
	/**
	 * Crea y devuelve la instancia del boton jbtnLine.
	 * @return
	 */
	private JButton getJbtnLine(){
		if(this.jbtnLine == null){
			this.jbtnLine = new JButton("", new ImageIcon(getClass().getResource("/org/unedvirtualslate/rsc/line_normal_begin.png")));
		}
		this.jbtnLine.setSize(25, 25);
		//this.jbtnLine.setLocation(35, 5);
		this.jbtnLine.setToolTipText("Permite hacer una linea recta.");
		this.jbtnLine.setActionCommand(CanvasPanel.LINE + "");
		this.jbtnLine.addActionListener(logic);
		return this.jbtnLine;
	}
	
	/**
	 * Crea y devuelve la instancia del boton jbtnFreeHand.
	 * @return
	 */
	private JButton getJbtnFreeHand(){
		if(this.jbtnFreeHand == null){
			this.jbtnFreeHand = new JButton("", new ImageIcon(getClass().getResource("/org/unedvirtualslate/rsc/pencil.png")));
		}
		this.jbtnFreeHand.setSize(25, 25);
		//this.jbtnFreeHand.setLocation(5, 5);
		this.jbtnFreeHand.setToolTipText("Permite dibujar a mano alzada.");
		this.jbtnFreeHand.setActionCommand(CanvasPanel.FREE_HAND + "");
		this.jbtnFreeHand.addActionListener(logic);
		return this.jbtnFreeHand;
	}

	/**
	 * Crea y devuelve la instancia del boton jbtnSquare.
	 * @return
	 */
	private JButton getJbtnSquare(){
		if(this.jbtnSquare == null){
			this.jbtnSquare = new JButton("", new ImageIcon(getClass().getResource("/org/unedvirtualslate/rsc/14_rectangle.png")));
		}
		this.jbtnSquare.setSize(25, 25);
		//this.jbtnFreeHand.setLocation(5, 5);
		this.jbtnSquare.setToolTipText("Permite dibujar un rectangulo.");
		this.jbtnSquare.setActionCommand(CanvasPanel.SQUARE + "");
		this.jbtnSquare.addActionListener(logic);
		return this.jbtnSquare;
	}
	
	/**
	 * Crea y devuelve la instancia del boton jbtnOval.
	 * @return
	 */
	private JButton getJbtnOval(){
		if(this.jbtnOval == null){
			this.jbtnOval = new JButton("", new ImageIcon(getClass().getResource("/org/unedvirtualslate/rsc/14_ellipse.png")));
		}
		this.jbtnOval.setSize(25, 25);
		//this.jbtnFreeHand.setLocation(5, 5);
		this.jbtnOval.setToolTipText("Permite dibujar un circulo.");
		this.jbtnOval.setActionCommand(CanvasPanel.OVAL + "");
		this.jbtnOval.addActionListener(logic);
		return this.jbtnOval;
	}
	
	/**
	 * Crea y devuelve la instancia del boton jbtnRoundRectangle.
	 * @return
	 */
	private JButton getJbtnRoundRectangle(){
		if(this.jbtnRounRectangle == null){
			this.jbtnRounRectangle = new JButton("", new ImageIcon(getClass().getResource("/org/unedvirtualslate/rsc/14_roundrect.png")));
		}
		this.jbtnRounRectangle.setSize(25, 25);
		//this.jbtnFreeHand.setLocation(5, 5);
		this.jbtnRounRectangle.setToolTipText("Permite dibujar un rectángulo con las esquinas redondeadas.");
		this.jbtnRounRectangle.setActionCommand(CanvasPanel.ROUND_RECT + "");
		this.jbtnRounRectangle.addActionListener(logic);
		return this.jbtnRounRectangle;
	}
}
